<?php

set_time_limit(10);

header( "Expires: " . gmdate("D, d M Y H:i:s") . "GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );

require_once '../include/common.inc.php';
require_once '../include/upfile.class.php';

getMyParam('type');
getMyParam('span_id');
getMyParam('id');

if (!checkAdmin()) {
    echo '<span id="edit_area" class=color_red>Timeout,please <a href="index.php">login</a> again<br><br></span>';
    exit;
}


if ($type == 1) {
    $sql = "SELECT `id`, `fid`, `name`, `pic`, `pic_2`, `e_catalogue`, `seq`, `description`, `publish` FROM `category` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);

    $img_show = $rs['pic'] != "" ? '<img src="../attachments/' . $rs['pic'] . '" border=0><br>' : '';
    $img_show2 = $rs['pic_2'] != "" ? '<img src="../attachments/' . $rs['pic_2'] . '" border=0><br>' : '';
    $e_catalogue = $rs['e_catalogue'] != "" ? '<a href="../attachments/' . $rs['e_catalogue'] . '">' . $rs['e_catalogue'] . '</a><br>' : '';

    $sql = "SELECT `id`, `name` FROM `category` WHERE `fid` = 0 ORDER BY `seq`";
    $query = $db->query($sql);
    while($rs1 = $db->fetch_array($query)) {
        $category_ary[$rs1['id']] = $rs1['name'];
    }
    $s = '';
    foreach ($category_ary as $k=>$v) {
        $selected = ($k == $rs['fid']) ? 'selected' : '';
        $s .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
    }
	$op_publish="";
	if($rs["publish"]==1)
		$op_publish="<option value=\"1\" selected>Yes</option>\n<option value=\"0\">No</option>";
	else
		$op_publish="<option value=\"1\">Yes</option>\n<option value=\"0\" selected>No</option>";	
	
                    
                    
	
    $out_str ='<span id="edit_area"><form action="p_category.php" method="post" name="form1" enctype="multipart/form-data"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td>Name :</td>
                <td>
                  <input type="text" class="text" name="name" value="' . $rs['name'] . '">	  
                  <input name="action" type="hidden" value="edit">
                  <input name="cid" type="hidden" value="' . $id . '">
                </td>
              </tr>  
              
              <tr> 
                <td>Parent Category :</td>
                <td>
                  <select class="select" name="fid">
                    <option value="0">--none--</option>
                    ' . $s . '
                  </select>	  
                </td>
              </tr>
              <tr> 
                <td>Publish :</td>
                <td>
                  <select class="select" name="publish">
				  ' . $op_publish . '
                  </select>	  
                </td>
              </tr>              <tr> 
                <td valign="top">Picture :</td>
                <td>
                  ' . $img_show . '<input type="file" class="text" name="up_pic" size=50>	  
                </td>
              </tr>          
              
              <tr> 
                <td valign="top">Guide Picture :</td>
                <td>
                  ' . $img_show2 . '<input type="file" class="text" name="up_pic2" size=50>	  
                </td>
              </tr>
              
              <tr> 
                <td valign="top">e-Catalogue :</td>
                <td>
                  ' . $e_catalogue . '<input type="file" class="text" name="e_catalogue" size=50>	  
                </td>
              </tr>
                  
              <tr> 
                <td>Description :</td>
                <td>
                  <textarea class="text" name="description" cols="60" rows="4" >' . htmlentities($rs['description']) . '</textarea>
                </td>
              </tr>              
              <tr> 
                <td>Sequence :</td>
                <td><input type="text" class="text" name="seq" size=3 value="' . $rs['seq'] . '"></td>
              </tr>            
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';

} elseif ($type == 2) {
    $sql = "SELECT `id`, `name`, `seq`, `type`, `pic` FROM `inventory` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    $inventory_type_list = '';
    foreach ($INVENTORY_TYPE_ARY as $k=>$v) {
        $select_flag = $k == $rs['type'] ? "selected" : "";
        $inventory_type_list .= '<option value="' . $k . '" ' . $select_flag . '>' . $v . '</option>';
    }

    $img_show = $rs['pic'] != "" ? '<img src="../attachments/' . $rs['pic'] . '" border=0><br>' : '';

    $out_str ='<span id="edit_area"><form action="p_inventory.php" method="post" name="form1" enctype="multipart/form-data"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td>Name :</td>
                <td>
                  <input type="text" class="text" name="name" value="' . $rs['name'] . '">	  
                  <input name="action" type="hidden" value="edit">
                  <input name="iid" type="hidden" value="' . $id . '">
                </td>
              </tr>                         
              <tr> 
                <td>Inventory type :</td>
                <td>
                  <select class="select" name="type">
                  ' . $inventory_type_list . '
                  </select>
                </td>
              </tr>      
              
              <tr> 
                <td>Picture :</td>
                <td>
                  ' . $img_show . '<input type="file" class="text" name="up_pic" size=50>	  
                </td>
              </tr>
                  
              <tr> 
                <td>Sequence :</td>
                <td><input type="text" class="text" name="seq" size=3 value="' . $rs['seq'] . '"></td>
              </tr>            
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';

} elseif ($type == 3) { 
    // All inventory
    $sql = "SELECT `id`, `name`, `seq`, `type` FROM `inventory` ORDER BY `seq`";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $inventory_ary[] = $rs;
    }
    $inventory_ary_num = count($inventory_ary);

    // select inventory
    $inventory_have_selected_ary = array();
    $inventory_qty_ary = array();
    $inventory_sp_ary = array();
    $inventory_sp2_ary = array();
    
    $sql = "SELECT `inventory_id`, `qty`, `special_price`, `special_price2` FROM `product_inventory` WHERE `product_id` = '$id'";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $inventory_have_selected_ary[] = $rs['inventory_id'];
        $inventory_qty_ary[$rs['inventory_id']] = $rs['qty'];
        $inventory_sp_ary[$rs['inventory_id']] = $rs['special_price'];
        $inventory_sp2_ary[$rs['inventory_id']] = $rs['special_price2'];
    }


    // All category
    $sql = "SELECT `id`, `name`  FROM `category` WHERE `fid` = 0 ORDER BY `seq`";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $category_ary[] = $rs;
    }
    $category_ary_num = count($category_ary);
    $sql = "SELECT `id`, `fid`, `name` FROM `category` WHERE `fid` > 0 ORDER BY `seq` ASC";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $sub_category_select_ary[$rs['fid']][$rs['id']] = $rs['name'];
    }

    // select category
    $category_have_selected_ary = array();
    $category_seq_value_ary = array();

    $sql = "SELECT `category_id`, `seq` FROM `product_category` WHERE `product_id` = '$id'";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $category_have_selected_ary[] = $rs['category_id'];
        //$rs['seq'] = $rs['seq'] == 0 ? "" : $rs['seq'];
        //$rs['seq2'] = $rs['seq2'] == 0 ? "" : $rs['seq2'];
        $category_seq_value_ary[$rs['category_id']] = $rs['seq'];
        //$category_seq2_value_ary[$rs['category_id']] = $rs['seq2'];
    }

/*
echo "<pre>";
print_r($inventory_ary);
print_r($inventory_qty_ary);
exit;
//admin/getdo.php?type=3&span_id=edit_area&id=9
*/

    $inventor_select_str = '';
    for($i=0; $i<$inventory_ary_num; $i++){
        $checked2 = "";
        $disabled2 = "disabled";
        if (in_array($inventory_ary[$i]['id'], $inventory_have_selected_ary)) {
            $checked2 = "checked";
            $disabled2 = "";
        }
        
        
        
        //$inventor_select_str .= '<option value="' . $inventory_ary[$i]['id'] . '" ' . $selected . '>' . $inventory_ary[$i]['name'] . '</option>';
        
        $inventory_qty_ary[$inventory_ary[$i]['id']] = isset($inventory_qty_ary[$inventory_ary[$i]['id']]) ? $inventory_qty_ary[$inventory_ary[$i]['id']] : 0;
        $inventory_sp_ary[$inventory_ary[$i]['id']] = isset($inventory_sp_ary[$inventory_ary[$i]['id']]) ? $inventory_sp_ary[$inventory_ary[$i]['id']] : 0;
        $inventory_sp2_ary[$inventory_ary[$i]['id']] = isset($inventory_sp2_ary[$inventory_ary[$i]['id']]) ? $inventory_sp2_ary[$inventory_ary[$i]['id']] : 0;
        
        // ΪHK warehouse Ҫ2sp
        if ($inventory_ary[$i]['type'] == 1) {
            $ovr_desc = 'Ovr ';
            $hk_sp = ' HK <input id="sp2_' . $inventory_ary[$i]['id'] . '" value="' . $inventory_sp2_ary[$inventory_ary[$i]['id']] . '" type="text" name="sp2_ary[' . $inventory_ary[$i]['id'] . ']" size="5"  ' . $disabled2 . ' />';
        } else {
            $ovr_desc = '';
            $hk_sp = '<input id="sp2_' . $inventory_ary[$i]['id'] . '" value="0" type="hidden" name="sp2_ary[' . $inventory_ary[$i]['id'] . ']"  ' . $disabled2 . ' />';
        }
        
        $inventor_select_str .= '<tr class="tbcontent1">
                      <td align="left"><input type="checkbox" name="inventory_id[]" value="' . $inventory_ary[$i]['id'] . '" onchange="if ( this.checked==true){qty_' . $inventory_ary[$i]['id'] . '.disabled=false;sp_' . $inventory_ary[$i]['id'] . '.disabled=false;sp2_' . $inventory_ary[$i]['id'] . '.disabled=false;} else {qty_' . $inventory_ary[$i]['id'] . '.disabled=true;sp_' . $inventory_ary[$i]['id'] . '.disabled=true;sp2_' . $inventory_ary[$i]['id'] . '.disabled=true;}" ' . $checked2 . ' />' . $inventory_ary[$i]['name'] . '</td>
                      <td align="center"><input id="qty_' . $inventory_ary[$i]['id'] . '" value="' . $inventory_qty_ary[$inventory_ary[$i]['id']] . '" type="text" name="qty_ary[' . $inventory_ary[$i]['id'] . ']" size="3"  ' . $disabled2 . ' /></td>
                      <td align="center">' . $ovr_desc . '<input id="sp_' . $inventory_ary[$i]['id'] . '" value="' . $inventory_sp_ary[$inventory_ary[$i]['id']] . '" type="text" name="sp_ary[' . $inventory_ary[$i]['id'] . ']" size="5"  ' . $disabled2 . ' /> ' . $hk_sp . '</td>
                    </tr>';
    }

    $category_select_str = '<tr class="tbheader">
                      <td align="left">Category/Sub Category</td>
                      <td align="center">Product Sequence</td>
                    </tr>';
    for($i=0; $i<$category_ary_num; $i++){
        $checked = "";
        $disabled = "disabled";
        if (in_array($category_ary[$i]['id'], $category_have_selected_ary)) {
            $checked = "checked";
            $disabled = "";
        }
        
        $category_seq_value_ary[$category_ary[$i]['id']] = isset($category_seq_value_ary[$category_ary[$i]['id']]) ? $category_seq_value_ary[$category_ary[$i]['id']] : 0;
       
        $s =       '<tr class="tbcontent1">
                      <td align="left"><input type="checkbox" name="category_id[]" value="' . $category_ary[$i]['id'] . '" onchange="if ( this.checked==true){seq_' . $category_ary[$i]['id'] . '.disabled=false;} else {seq_' . $category_ary[$i]['id'] . '.disabled=true;}"  ' . $checked . ' />' . $category_ary[$i]['name'] . '</td>
                      <td align="center"><input id="seq_' . $category_ary[$i]['id'] . '" type="text" name="category_seq[' . $category_ary[$i]['id'] . ']" value="' . $category_seq_value_ary[$category_ary[$i]['id']] . '" size="3" ' . $disabled . ' /></td>             
                    </tr>';

        $ss = '';
        if (!empty($sub_category_select_ary[$category_ary[$i]['id']])) {
            $s =       '<tr class="tbcontent1"  height="20">
                      <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $category_ary[$i]['name'] . '</td>
                      <td align="center"></td>
                    </tr>';
            foreach ($sub_category_select_ary[$category_ary[$i]['id']] as $k1=>$v1) {
                $checked1 = "";
                $disabled1 = "disabled";
                if (in_array($k1, $category_have_selected_ary)) {
                    $checked1 = " checked";
                    $disabled1 = "";
                }
                
                $category_seq_value_ary[$k1] = isset($category_seq_value_ary[$k1]) ? $category_seq_value_ary[$k1] : 0;
        
//                $ss .= '<tr class="tbcontent1">
//                      <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="category_id[]" value="' . $k1 . '" onchange="if ( this.checked==true){seq_' . $k1 . '.disabled=false;} else {seq_' . $k1 . '.disabled=true;}" ' . $checked1 . ' />' . $v1 . '</td>
//                      <td align="center"><input id="seq_' . $k1 . '" type="text" name="category_seq[' . $k1 . ']" value="' . $category_seq_value_ary[$k1] . '" size="3" ' . $disabled1 . ' /></td>
//                    </tr>';
				$ss .= '<tr class="tbcontent1">
                      <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="category_id[]" value="' . $k1 . '" onchange="if(this.checked==true) document.getElementById(\'seq_'.$k1.'\').disabled=false;else document.getElementById(\'seq_'.$k1.'\').disabled=true;" ' . $checked1 . ' />' . $v1 . '</td>
                      <td align="center"><input id="seq_' . $k1 . '" type="text" name="category_seq[' . $k1 . ']" value="' . $category_seq_value_ary[$k1] . '" size="3" ' . $disabled1 . ' /></td>
                    </tr>';
            }
        }
        $category_select_str .= $s . $ss;
    }

    $sql = "SELECT * FROM `product` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
 
    if ($rs['new_flag'] == 1) {
        $new_selected_yes = "selected";
        $new_selected_no = "";
    } else {
        $new_selected_yes = "";
        $new_selected_no = "selected";
    }

    if ($rs['hidden_flag'] == 1) {
        $hidden_flag_selected_yes = "selected";
        $hidden_flag_selected_no = "";
    } else {
        $hidden_flag_selected_yes = "";
        $hidden_flag_selected_no = "selected";
    }

    $img_show = "";
    if ($rs['pic'] != "") {
        $img_show = '<img src="../attachments/' . $rs['pic'] . '" border=0><br>';
    }
    $img_show2 = "";
    if ($rs['small_pic'] != "") {
        $img_show2 = '<img src="../attachments/' . $rs['small_pic'] . '" border=0><br>';
    }

    $out_str ='<!--iframe name="getdoiframe" width=0 height=0 src="about:blank" id="getdoiframe"></iframe  target="getdoiframe"--><span id="edit_area"><form action="p_product.php" method="post" name="form1" enctype="multipart/form-data"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <tr valign="vtop"> 
                <td>Code :</td>
                <td>
                  <input type="text" class="text" name="code" value="' . $rs['code'] . '">	  
                  <input name="action" type="hidden" value="edit">
                  <input name="pid" type="hidden" value="' . $id . '">
                </td>
              </tr>
              <tr valign="vtop"> 
                <td>Name :</td>
                <td><textarea class="text" name="name" cols="40" rows="2"  >' . htmlentities($rs['name']) . '</textarea></td>
              </tr>
              <tr valign="vtop"> 
                <td>Small Picture :</td>
                <td>' . $img_show2 . '<input type="file" class="text" name="up_small_pic" size=50></td>
              </tr>
              <tr valign="vtop"> 
                <td>Picture :</td>
                <td>' . $img_show . '<input type="file" class="text" name="up_pic" size=50></td>
              </tr>
              <tr valign="vtop"> 
                <td>Finish Shown :</td>
                <td><input type="text" class="text" name="finishshown" value="' . $rs['finishshown'] . '"> </td>
              </tr>
              <tr valign="vtop"> 
                <td>Fabric Shown :</td>
                <td><input type="text" class="text" name="fabricshown" value="' . $rs['fabricshown'] . '"> </td>
              </tr>
              <tr valign="vtop"> 
                <td>Leather Shown :</td>
                <td><input type="text" class="text" name="leathershown" value="' . $rs['leathershown'] . '"> </td>
              </tr>
              <tr valign="vtop"> 
                <td>Marble Shown :</td>
                <td><input type="text" class="text" name="marbleshown" value="' . $rs['marbleshown'] . '"> </td>
              </tr>
              <tr valign="vtop"> 
                <td>Depth :</td>
                <td><input type="text" class="text" name="length" value="' . $rs['length'] . '"> CM</td>
              </tr>
              <tr valign="vtop"> 
                <td>Width :</td>
                <td><input type="text" class="text" name="width" value="' . $rs['width'] . '"> CM</td>
              </tr>
              <tr valign="vtop"> 
                <td>Height :</td>
                <td><input type="text" class="text" name="height" value="' . $rs['height'] . '"> CM</td>
              </tr>
              
              <tr valign="vtop"> 
                <td>Depth :</td>
                <td><input type="text" class="text" name="length2" value="' . $rs['length2'] . '"> INCH</td>
              </tr>
              <tr valign="vtop"> 
                <td>Width :</td>
                <td><input type="text" class="text" name="width2" value="' . $rs['width2'] . '"> INCH</td>
              </tr>
              <tr valign="vtop"> 
                <td>Height :</td>
                <td><input type="text" class="text" name="height2" value="' . $rs['height2'] . '"> INCH</td>
              </tr>
              
              <tr valign="vtop"> 
                <td>Cbm :</td>
                <td><input type="text" class="text" name="cbm" value="' . $rs['cbm'] . '"></td>
              </tr>             
              <tr valign="vtop"> 
                <td>Cuft :</td>
                <td><input type="text" class="text" name="cuft" value="' . $rs['cuft'] . '"></td>
              </tr>  
              
              <tr valign="vtop"> 
                <td>Price : </td>
                <td>
                  <input type="text" class="text" name="price_1" size="10"  value="' . $rs['price_1'] . '"  > (USD) Mixed Container Price <br> 
                  <input type="text" class="text" name="price_2" size="10" value="' . $rs['price_2'] . '"  > (USD) Direct Container Price <br>
                  <input type="text" class="text" name="price_3" size="10" value="' . $rs['price_3'] . '"  > (HKD) Hong Kong Wholesaler Price <br>
                  
                </td>
              </tr>
              <tr valign="vtop"> 
                <td>New Item :</td>
                <td>							  
                  <select class="select" name="new_flag"  >
                  <option value=1 ' . $new_selected_yes . '>Yes</option><option value=0 ' . $new_selected_no . '>No</option></select> 
                </td>
              </tr>
              
              <tr valign="vtop"> 
                <td>Hidden in product :</td>
                <td>							  
                  <select class="select" name="hidden_flag"  >
                  <option value=1 ' . $hidden_flag_selected_yes . '>Yes</option><option value=0 ' . $hidden_flag_selected_no . '>No</option></select> 
                </td>
              </tr>
              <tr valign="vtop"> 
                <td>Description :</td>
                <td><textarea class="text" name="comment" cols="40" rows="4"  >' . stripslashes($rs['comment']) . '</textarea></td>
              </tr>
              
              <tr valign="vtop"> 
                <td>Inventory :</td>
                <td>
                  <table width="100%" border="0" cellspacing="1" cellpadding="1" class="tb">
                    <tr class="tbheader">
                      <td align="left">Inventory</td>
                      <td align="center">Available Qty</td>
                      <td align="center">Special Price</td>
                    </tr>					
                    ' . $inventor_select_str . '
                  </table>     
                </td>
              </tr>
              <tr valign="vtop"> 
                <td>category :</td>
                <td>
                    <table width="100%" border="0" cellspacing="1" cellpadding="1" class="tb">
                    ' . $category_select_str . '
                    </table>
                </td>
              </tr>
              <tr valign="vtop"> 
                <td align="right" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';

} elseif ($type == 4) {
    $sql = "SELECT * FROM `user` WHERE `id` = '$id' AND `type` = 10";
    $rs = $db->get_one($sql);

    $out_str ='<span id="edit_area"><form action="user.php" method="post" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td>Name :</td>
                <td>
                  <input type="text" class="text" name="name" value="' . $rs['username'] . '">	  
                  <input name="action" type="hidden" value="edit">
                  <input name="uid" type="hidden" value="' . $id . '">
                </td>
              </tr>
              
              <!--tr> 
                <td>True Name :</td>
                <td>
                  <input type="text" class="text" name="firstname" value="' . $rs['firstname'] . '">	  
                </td>
              </tr-->             
              
              <tr> 
                <td>Email :</td>
                <td>
                  <input type="text" class="text" name="email" value="' . $rs['email'] . '" size=30>	  
                </td>
              </tr>
              
              <tr> 
                <td>Tel :</td>
                <td>
                  <input type="text" class="text" name="phone" value="' . $rs['phone'] . '" size=30>	  
                </td>
              </tr>
              
              <tr> 
                <td>Fax :</td>
                <td>
                  <input type="text" class="text" name="fax" value="' . $rs['fax'] . '" size=30>	  
                </td>
              </tr>              
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 5) {
    $img_show = "";

    $sql = "SELECT * FROM `news` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    if ($rs['pic'] != "") {
        $img_show = '<img src="../attachments/' . $rs['pic'] . '" border=0><br>';
    }
    $yes_checked = $no_checked = "";
    if ($rs['publish_flag'] == 1) {
        $yes_checked = "checked";
    } else {
        $no_checked = "checked";
    }
    $out_str ='<span id="edit_area"><form action="i_news.php" method="post"  onSubmit="return validate(this)" name="form1" enctype="multipart/form-data"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Subject :</td>
                <td><input type="text" class="text" name="subject" size="36" value="' . $rs['subject'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="nid" value="' . $rs['id'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Address :</td>
                <td><input type="text" class="text" name="address" size="56" value="' . $rs['address'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Details : </td>
                <td><textarea class="text" name="details" cols="55" rows="20">' . $rs['details'] . '</textarea></td>
              </tr>
              <tr> 
                <td class="tdheader">Picture :</td>
                <td>' . $img_show . '<input type="file" class="text" name="up_pic" size=45>
              </tr>
              <tr> 
                <td class="tdheader">Publish :</td>
                <td> <input type="radio" name="publish" value="1" ' . $yes_checked . '>
                  yes 
                  <input type="radio" name="publish" value="0" ' . $no_checked . '>
                  no </td>
              </tr>
              <tr>
                <td valign="top" class="tdheader">Set Time :</td>
                <td><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
                    <tr>
                      <td height="68" bgcolor="#F5F8FD"><table border="0" cellspacing="5" cellpadding="1">
                          <tr> 
                            <td>Online Date: 
                              <input type="text" name="online" class="text" value="' . date("Y-m-d H:i", $rs['online']) . '"><!--e.g. 2000-01-01 10:00--></td>
                          </tr>
                          <tr> 
                            <td>Offline Date: 
                              <input type="text" name="offline" class="text" value="' . date("Y-m-d H:i", $rs['offline']) . '"></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                  
                </td>
              </tr>    
              
                
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 6) {
    $out_str ='<span id="edit_area"><form action="i_links.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">title :</td>
                <td><input type="text" class="text" name="title" size="36">
                <input type="hidden" name="action" value="add"></td>
              </tr>
              <tr> 
                <td class="tdheader">url :</td>
                <td><input type="text" class="text" name="url" size="56" value="http://"></td>
              </tr>
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3"></td>
              </tr>              
              <tr> 
                <td class="tdheader">Publish :</td>
                <td> <input type="radio" name="publish" value="1" checked>
                  yes 
                  <input type="radio" name="publish" value="0" >
                  no </td>
              </tr>            
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 7) {
    $sql = "SELECT * FROM `links` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    $yes_checked = $no_checked = "";
    if ($rs['publish_flag'] == 1) {
        $yes_checked = "checked";
    } else {
        $no_checked = "checked";
    }
    $out_str ='<span id="edit_area"><form action="i_links.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">title :</td>
                <td><input type="text" class="text" name="title" size="36" value="' . $rs['title'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="lid" value="' . $rs['id'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">url :</td>
                <td><input type="text" class="text" name="url" size="56" value="' . $rs['url'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"></td>
              </tr>              
              <tr> 
                <td class="tdheader">Publish :</td>
                <td> <input type="radio" name="publish" value="1" ' . $yes_checked . '>
                  yes 
                  <input type="radio" name="publish" value="0" ' . $no_checked . '>
                  no </td>
              </tr>            
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 8) {
    $sql = "SELECT * FROM `distribution` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    
    ksort($AREA_ARY);
    foreach ($AREA_ARY as $k=>$v) {
        
        if ($v['id'] == $rs['area']) {
            $area_select .= '<option value="' . $v['id'] . '" selected>' . $v['name'] . '</option>';
        } else {
            $area_select .= '<option value="' . $v['id'] . '" >' . $v['name'] . '</option>';
        }
    }

    $out_str ='<span id="edit_area"><form action="i_distribution.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Area :</td>
                <td>
                <select name="area" class="text">
		        <option value="" selected>---Please Select---</option>
		        ' . $area_select . '	
		        </select>
                <input type="hidden" name="action" value="edit"><input type="hidden" name="did" value="' . $rs['id'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Country :</td>
                <td><input type="text" class="text" name="country" size="36" value="' . $rs['country'] . '"></td>
              </tr>                    
             
              <tr> 
                <td class="tdheader">Type :</td>
                <td><input type="text" class="text" name="type" size="36" value="' . $rs['type'] . '"></td>
              </tr>
                            
              
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"> </td>
              </tr>    
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 9) {
    $sql = "SELECT * FROM `photo` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    if ($rs['pic'] != "") {
        $img_show = '<img src="../attachments/' . $rs['pic'] . '" border=0><br>';
    }

    $photo_category_ary = array();
    $sql = "SELECT `id`, `name` FROM `photo_category` ORDER BY `seq` ASC, `id` DESC";
    $query = $db->query($sql);
    while($rs1 = $db->fetch_array($query)) {
        $photo_category_ary[$rs1['id']] = $rs1['name'];
    }

    $category_str = '';
    foreach ($photo_category_ary as $k=>$v) {
        $selected = "";
        if (isset($rs['photo_category_id']) && $rs['photo_category_id'] == $k) {
            $selected = "selected";
        }
        $category_str .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
    }

    $out_str ='<span id="edit_area"><form action="i_photo.php" method="post"  onSubmit="return validate(this)" enctype="multipart/form-data" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Name :</td>
                <td><input type="text" class="text" name="name" size="36" value="' . $rs['name'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="pid" value="' . $rs['id'] . '"></td>
              </tr>
              

              
              <tr> 
                <td class="tdheader">Photo Category :</td>
                <td>
                  <select class="select" name="photo_category_id">' . $category_str . '
                  </select>	  
                </td>
              </tr>
              <tr> 
                <td class="tdheader">Photo :</td>
                <td>' . $img_show . '<input type="file" class="text" name="up_pic" size="45"> </td>
              </tr>
              <tr> 
                <td class="tdheader">Description : </td>
                <td><textarea class="text" name="description" cols="55" rows="20">' . htmlentities($rs['description']) . '</textarea></td>
              </tr>
              
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"></td>
              </tr>
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 10) {
    $out_str ='<span id="edit_area"><form action="i_photo_category.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Name :</td>
                <td><input type="text" class="text" name="name" size="36">
                <input type="hidden" name="action" value="add"></td>
              </tr>
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3"></td>
              </tr>                  
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 11) {
    $sql = "SELECT * FROM `photo_category` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    $out_str ='<span id="edit_area"><form action="i_photo_category.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Name :</td>
                <td><input type="text" class="text" name="name" size="36" value="' . $rs['name'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="cid" value="' . $rs['id'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"></td>
              </tr>                    
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 12) {

    $sql = "SELECT * FROM `user` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);

    foreach ($STATE_ARY as $k=>$v) {
        $select_str = $rs['stateid'] == $k ? 'selected' : '';
        $state_select .= '<option value="' . $k . '" ' . $select_str . '>' . $v . '</option>';
        if ($k==51) {
            $state_select .= '<option value="">--------------------------</option><option value="">CANADIAN PROVINCES</option><option value="">--------------------------</option>';
        }
    }
    foreach ($COUNTRY_ARY as $k=>$v) {
        $select_str = $rs['countryid'] == $k ? 'selected' : '';
        $country_select .= '<option value="' . $k . '" ' . $select_str . '>' . $v . '</option>';
    }
    
    $tmp_ary = array('Importer', 'Wholesaler', 'Retailer', 'Designer', 'other');
    foreach ($tmp_ary as $v) {
        $select_str = $rs['business_type'] == $v? 'selected' : '';
        $business_type_select .= '<option value="' . $v . '" ' . $select_str . '>' . $v . '</option>';
    }
    
    $type_select = $status_select = '';
    foreach ($USER_TYPE_ARY as $k=>$v) {
        $selected = $k==$rs['type'] ? "selected" : "";
        $type_select .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
    }
    foreach ($USER_STATUS_ARY as $k=>$v) {
        $selected = $k==$rs['status'] ? "selected" : "";
        $status_select .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
    }
    
    $out_str ='<span id="edit_area"><form action="c_customer_list.php" method="post"  onSubmit="return validate(this)" name="form1">
                <input type="hidden" name="action" value="edit">
                <input type="hidden" name="uid" value="' . $id . '">
                <table width="100%" border="0" cellspacing="1" cellpadding="1">
              
                    <tr><td colspan=2><span id="msg_area"></span></td></tr>
		                        
		                        <tr><td colspan=2  height=5></td></tr>
		                        
		                        
		                        <tr class="tdheader">
		                            <td align="right">Company:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquirycompany" class="form" size="30" value="' . $rs['company'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">First Name:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryfirstname" class="form" size="30" value="' . $rs['firstname'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Last Name:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquirylastname" class="form" size="30" value="' . $rs['lastname'] . '"></td>
		                        </tr>
		                        
		                        <tr class="tdheader">
		                            <td align="right">Username:</td>
		                            <td align="left">
		                              <input type="text" class="text" name="dealerinquiryusername" class="form" size="30" value="' . $rs['username'] . '">
		                              <input type="hidden" class="text" name="old_dealerinquiryusername"  value="' . $rs['username'] . '">
		                            </td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Password:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquirypassword2" class="form" size="30" value="' . $rs['password2'] . '" readonly></td>
		                        </tr>
		                        
		                        <tr class="tdheader">
		                            <td align="right">Business Type:</td>
		                            <td align="left">
		                            <select name="dealerinquirybusinesstype" class="select">
									  <option value="">---Please Select---</option>
									  ' . $business_type_select . '
									</select>
		                            </td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Years In Business:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryyearsinbusiness" class="form" size="30" value="' . $rs['business_year'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Address:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryaddress" class="form" size="30" value="' . $rs['address'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Address 2:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryaddress2" class="form" size="30" value="' . $rs['address2'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">City:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquirycity" class="form" size="30" value="' . $rs['city'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">State/Province:</td>
		                            <td align="left">
		                            <select name="stateid" class="select">
		                              <option value="">---Please Select---</option>
		                              ' . $state_select . '
		                            </select>
		                          </td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Country:</td>
		                            <td align="left">
		                            <select name="countryid" class="select">
		                              <option value="">---Please Select---</option>
		                              ' . $country_select . '	
		                            </select>
		                            </td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Zip/Postal Code:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquirypostal" class="form" size="30" value="' . $rs['zip'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Phone:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryphone" class="form" size="30" value="' . $rs['phone'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Fax:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryfax" class="form" size="30" value="' . $rs['fax'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Email:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryemail" class="form" size="30" value="' . $rs['email'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Company Registration Number:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryregistrationnumber" class="form" size="30" value="' . $rs['company_number'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">URL:</td>
		                            <td align="left"><input type="text" class="text" name="dealerinquiryurl" class="form" size="30" value="' . $rs['url'] . '"></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Where did you find us:</td>
		                            <td align="left"><textarea class="text" name="find_us_content" cols="66" rows="4">' . htmlentities($rs['find_us_content']) . '</textarea></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Comments:</td>
		                            <td align="left"><textarea class="text" name="comments" cols="66" rows="4">' . htmlentities($rs['comments']) . '</textarea></td>
		                        </tr>
		                        <tr class="tdheader">
		                            <td align="right">Info about your company:</td>
		                            <td align="left"><textarea class="text" name="company_content" cols="66" rows="5">' . htmlentities($rs['company_content']) . '</textarea></td>
		                        </tr>	 
		                        
		                        <tr> 
                                    <td class="tdheader" align="right">Type :</td>
                                    <td>
                                      <select class="select" name="typeid">
                                        <option value="0">--Please select--</option>
                                        ' . $type_select . '
                                      </select>
                                    </td>
                                  </tr>                    
                                  <tr> 
                                    <td class="tdheader" align="right">Status :</td>
                                    <td>
                                      <select class="select" name="statusid">
                                        <option value="0">--Please select--</option>
                                        ' . $status_select . '
                                      </select><input name="pre_statusid" type="hidden" value="'.$rs["status"].'"/>
                                    </td>
                                  </tr>
              
                                <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 13) {
    $type_select = $status_select = '';
    foreach ($USER_TYPE_ARY as $k=>$v) {
        $type_select .= '<option value="' . $k . '" >' . $v . '</option>';
    }
    foreach ($USER_STATUS_ARY as $k=>$v) {
        $status_select .= '<option value="' . $k . '" >' . $v . '</option>';
    }
    $sql = "SELECT * FROM `user` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    $out_str ='<span id="edit_area"><form action="c_customer_list.php" method="post" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr><td class="tdheader" width=20% align=left>Company: </td><td align=left>' . $rs['company'] . '</td></tr>
              <tr><td class="tdheader" align=left>First Name: </td><td>' . $rs['firstname'] . '</td></tr>
              <tr><td class="tdheader" align=left>Last Name: </td><td>' . $rs['lastname'] . ' </td></tr>
              <tr><td class="tdheader" align=left>Business Type: </td><td>' . $rs['business_type'] . '</td></tr>
              <tr><td class="tdheader" align=left>Years In Business: </td><td>' . $rs['business_year'] . '</td></tr>
              <tr><td class="tdheader" align=left>Address: </td><td>' . $rs['address'] . '</td></tr>
              <tr><td class="tdheader" align=left>Address 2: </td><td>' . $rs['address2'] . '</td></tr>
              <tr><td class="tdheader" align=left>City: </td><td>' . $rs['city'] . '</td></tr>
              <tr><td class="tdheader" align=left>State/Province: </td><td>' . $STATE_ARY[$rs['stateid']] . '</td></tr>
              <tr><td class="tdheader" align=left>Country: </td><td>' . $COUNTRY_ARY[$rs['countryid']] . '</td></tr>
              <tr><td class="tdheader" align=left>Zip/Postal Code: </td><td>' . $rs['zip'] . '</td></tr>
              <tr><td class="tdheader" align=left>Phone: </td><td>' . $rs['phone'] . '</td></tr>
              <tr><td class="tdheader" align=left>Fax: </td><td>' . $rs['fax'] . '</td></tr>
              <tr><td class="tdheader" align=left>Email: </td><td>' . $rs['email'] . '</td></tr>
              <tr><td class="tdheader" align=left>Company Registration Number: </td><td>' . $rs['company_number'] . '</td></tr>
              <tr><td class="tdheader" align=left>URL: </td><td>' . $rs['url'] . '</td></tr>
              <tr><td class="tdheader" align=left>Where did you find us: </td><td>' . $rs['find_us_content'] . '</td></tr>
              <tr><td class="tdheader" align=left>Comments: </td><td>' . $rs['comments'] . '</td></tr>
              <tr><td class="tdheader" align=left>Info about your company: </td><td>' . $rs['company_content'] . '</td></tr>
              
              <input type="hidden" name="action" value="changestatus1">
              <input type="hidden" name="uid" value="' . $rs['id'] . '">

              <tr> 
                <td class="tdheader">Type :</td>
                <td>
                  <select class="select" name="typeid">
                    <option value="0">--Please select--</option>
                    ' . $type_select . '
                  </select>
                </td>
              </tr>                    
              <tr> 
                <td class="tdheader">Status :</td>
                <td>
                  <select class="select" name="statusid">
                    <option value="0">--Please select--</option>
                    ' . $status_select . '
                  </select>
                </td>
              </tr>
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 14) {
    $sql = "SELECT * FROM `user` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);

    $type_select = $status_select = '';
    foreach ($USER_TYPE_ARY as $k=>$v) {
        $type_selected = $k == $rs['type'] ? 'selected' : '';
        $type_select .= '<option value="' . $k . '" ' . $type_selected . '>' . $v . '</option>';
    }
    foreach ($USER_STATUS_ARY as $k=>$v) {
        $status_selected = $k == $rs['status'] ? 'selected' : '';
        $status_select .= '<option value="' . $k . '" ' . $status_selected . '>' . $v . '</option>';
    }

    $out_str ='<span id="edit_area"><form action="c_customer_list.php" method="post" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr><td class="tdheader" width=20% align=left>Company: </td><td align=left>' . $rs['company'] . '</td></tr>
              <tr><td class="tdheader" align=left>First Name: </td><td>' . $rs['firstname'] . '</td></tr>
              <tr><td class="tdheader" align=left>Last Name: </td><td>' . $rs['lastname'] . ' </td></tr>
              <tr><td class="tdheader" align=left>Business Type: </td><td>' . $rs['business_type'] . '</td></tr>
              <tr><td class="tdheader" align=left>Years In Business: </td><td>' . $rs['business_year'] . '</td></tr>
              <tr><td class="tdheader" align=left>Address: </td><td>' . $rs['address'] . '</td></tr>
              <tr><td class="tdheader" align=left>Address 2: </td><td>' . $rs['address2'] . '</td></tr>
              <tr><td class="tdheader" align=left>City: </td><td>' . $rs['city'] . '</td></tr>
              <tr><td class="tdheader" align=left>State/Province: </td><td>' . $STATE_ARY[$rs['stateid']] . '</td></tr>
              <tr><td class="tdheader" align=left>Country: </td><td>' . $COUNTRY_ARY[$rs['countryid']] . '</td></tr>
              <tr><td class="tdheader" align=left>Zip/Postal Code: </td><td>' . $rs['zip'] . '</td></tr>
              <tr><td class="tdheader" align=left>Phone: </td><td>' . $rs['phone'] . '</td></tr>
              <tr><td class="tdheader" align=left>Fax: </td><td>' . $rs['fax'] . '</td></tr>
              <tr><td class="tdheader" align=left>Email: </td><td>' . $rs['email'] . '</td></tr>
              <tr><td class="tdheader" align=left>Company Registration Number: </td><td>' . $rs['company_number'] . '</td></tr>
              <tr><td class="tdheader" align=left>URL: </td><td>' . $rs['url'] . '</td></tr>
              <tr><td class="tdheader" align=left>Where did you find us: </td><td>' . $rs['find_us_content'] . '</td></tr>
              <tr><td class="tdheader" align=left>Comments: </td><td>' . $rs['comments'] . '</td></tr>
              <tr><td class="tdheader" align=left>Info about your company: </td><td>' . $rs['company_content'] . '</td></tr>
              
              <input type="hidden" name="action" value="changestatus2">
              <input type="hidden" name="uid" value="' . $rs['id'] . '">

              <tr> 
                <td class="tdheader">Type :</td>
                <td>
                  <select class="select" name="typeid">
                    <option value="0">--Please select--</option>
                    ' . $type_select . '
                  </select>
                </td>
              </tr>                    
              <tr> 
                <td class="tdheader">Status :</td>
                <td>
                  <select class="select" name="statusid">
                    <option value="0">--Please select--</option>
                    ' . $status_select . '
                  </select>
                </td>
              </tr>
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 15) {
    $sql = "SELECT * FROM `order` WHERE `id` = '$id'";
    $order_info = $db->get_one($sql);

	$tmp_ary = explode("{}", $order_info['product_info']);
	$info_ary = array();
	if (!empty($tmp_ary)) {
	    foreach ($tmp_ary as $v) {
	        @list($type, $pid, $count, $price, $name) = explode("|", $v);
	        $cost = $count*$price;
	        $info_ary[$type . '_' . $pid] = array('name'=>$name, 'price'=>$price, 'count'=>$count, 'intype'=>$type, 'cost'=>$cost);
	    }
	}
	
    
    $total_qty = $order_info['totalcount'];
    $total_cost = $order_info['totalcost'];
    
    $all_product_info_ary = array();
    foreach ($info_ary as $pid=>$vv) {
        @list($type, $pid) = explode("_", $pid);
    	$pid_ary[] = $pid;
    	
    }
    if (!empty($pid_ary)) {
    	$pid_str = implode(",", $pid_ary);
    	$sql = "SELECT `id`, `code`, `small_pic` FROM `product` WHERE id IN (" . $pid_str . ")";
    	$query = $db->query($sql);
    	while($rs = $db->fetch_array($query)) {
    	    $all_product_info_ary[$rs['id']] = $rs;
    	}
    }
    
    $sql = "SELECT `id`, `username`, `firstname`, `lastname`, `city`, `countryid`, `type` FROM `user` WHERE `id` = '" . $order_info['user_id'] . "'";
	$user1_ary = $db->get_one($sql);
	$money_type = $user1_ary['type'] == 1 ? "HKD" : "USD";	

    $sql = "SELECT * FROM `inventory`";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $location_info_ary[$rs['id']] = $rs['name'];
    }

    $out_str = <<<EOT
    <span id="edit_area"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <tr class="cartAlternatingRowB"  height="30">
              <td align="left" valign="top" class="cartHeading" colspan=7>
              <strong>OrderId</strong>: $id
              <br><strong>Customer</strong>: {$user1_ary['firstname']}  
              <br><strong>City</strong>:  {$user1_ary['city']}
              <br><strong>Country</strong>: {$COUNTRY_ARY[$user1_ary['countryid']]}
              <br><br>
              </td>
              </tr>
              <tr class="cartAlternatingRowB"  height="30">
        						    <td align="center" valign="middle" class="cartHeading" width="40">View</td>
			    			        <td align="center" valign="middle" class="cartHeading" width="80">Sections</td>
        			    			<td align="left" valign="middle" class="cartHeading" width="80">Item No.</td>
        			    			<td align="left" valign="middle" class="cartHeading" width="200" colspan=2>Product</td>
        			    			<td align="center" valign="middle" class="cartHeading" width="60">Price<br>($money_type)</td>
        			    			<td align="center" valign="middle" class="cartHeading" width="40">QTY</td>
        			    			<td align="center" valign="middle" class="cartHeading" width="80">Total<br>($money_type)</td>
        						</tr>
        						<tr><td colspan=8 bgcolor="#A5AAB0" height=1></td></tr>
EOT;

foreach ($info_ary as $k=>$v) {
    @list($type, $k) = explode("_", $k);
    $location = $v['intype'] == 0 ? 'Products' : $location_info_ary[$v['intype']];
    
    if (trim($all_product_info_ary[$k]['small_pic']) == "" || !file_exists("../attachments/" . $all_product_info_ary[$k]['small_pic'])) {
        $all_product_info_ary[$k]['small_pic'] = 'no_40.gif';
    }
$out_str .= <<<EOT

        			            <tr class="cartAlternatingRowB1" height=45>
        			                <td align="center" valign="middle" width="45"><img src="{$web_url}attachments/{$all_product_info_ary[$k]['small_pic']}" border="0" class="picture" width="40" height="40"></td>
			    			        <td align="center" valign="middle" width="80">$location</td>			    			
        			    			<td align="left" valign="middle"  width="80">{$all_product_info_ary[$k]['code']}</td>
        			    			<td align="left" valign="middle"  width="200" colspan=2>{$v['name']} </td>
        			    			<td align="center" valign="middle" width="80">{$v['price']}</td>
        			    			<td align="center" valign="middle" width="40">{$v['count']}</td>
        			    			<td align="center" valign="middle">{$v['cost']}</td>
        						</tr>

EOT;
} 
$out_str .= <<<EOT
        						<tr><td colspan=8 bgcolor="#A5AAB0" height=1></td></tr>
        						<tr>
        						  <td colspan=7 height=25 align="right"><strong>Sub Total:  </strong></td>
        						  <td colspan=1 align="center">$total_cost $money_types</td>
        						</tr>   
        						
        						
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel('edit_area');">                   
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
            
          </span>
EOT;
} elseif ($type == 16) {
    $sql = "SELECT * FROM `tradeshows` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);

    $out_str ='<span id="edit_area"><form action="i_tradeshows.php" method="post"  onSubmit="return validate(this)" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Date :</td>
                <td><input type="text" class="text" name="date" size="36" value="' . $rs['date'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="tid" value="' . $rs['id'] . '"></td>
              </tr>
              
               <tr> 
                <td class="tdheader">End Date :</td>
                <td><input type="text" class="text" name="sdate" size="36" value="' . date('Y-m-d', $rs['sdate']) . '"></td>
              </tr>
              
              
              <tr> 
                <td class="tdheader">Show :</td>
                <td><input type="text" class="text" name="show" size="56" value="' . $rs['show'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Website :</td>
                <td><input type="text" class="text" name="website" size="56" value="' . $rs['website'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Location :</td>
                <td><input type="text" class="text" name="location" size="56" value="' . $rs['location'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">City :</td>
                <td><input type="text" class="text" name="city" size="56" value="' . $rs['city'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Country :</td>
                <td><input type="text" class="text" name="country" size="56" value="' . $rs['country'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Booth# :</td>
                <td><input type="text" class="text" name="booth" size="56" value="' . $rs['booth'] . '"></td>
              </tr>
              <tr> 
                <td class="tdheader">Company :</td>
                <td><input type="text" class="text" name="company" size="56" value="' . $rs['company'] . '"></td>
              </tr>
              <!--tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"></td>
              </tr-->
              
                
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 17) {
    $sql = "SELECT * FROM `photo` WHERE `id` = '$id'";
    $rs = $db->get_one($sql);
    if ($rs['pic'] != "") {
        $img_show = '<img src="../attachments/' . $rs['pic'] . '" border=0><br>';
    }

    $photo_category_ary = array();
    $sql = "SELECT `id`, `name` FROM `category` WHERE `fid` = 0 ORDER BY `seq` ASC, `id` DESC";
	$query = $db->query($sql);
	while($rs1 = $db->fetch_array($query)) {
	    $photo_category_ary[$rs1['id']] = $rs1['name'];
	}

    $category_str = '';
    foreach ($photo_category_ary as $k=>$v) {
        $selected = "";
        if (isset($rs['photo_category_id']) && $rs['photo_category_id'] == $k) {
            $selected = "selected";
        }
        $category_str .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
    }

    $out_str ='<span id="edit_area"><form action="p_product_gallery.php" method="post"  onSubmit="return validate(this)" enctype="multipart/form-data" name="form1"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              
              <tr> 
                <td class="tdheader">Name :</td>
                <td><input type="text" class="text" name="name" size="36" value="' . $rs['name'] . '">
                <input type="hidden" name="action" value="edit"><input type="hidden" name="pid" value="' . $rs['id'] . '"></td>
              </tr>
              

              
              <tr> 
                <td class="tdheader">Category :</td>
                <td>
                  <select class="select" name="photo_category_id">' . $category_str . '
                  </select>	  
                </td>
              </tr>
              <tr> 
                <td class="tdheader">Photo :</td>
                <td>' . $img_show . '<input type="file" class="text" name="up_pic" size="45"> </td>
              </tr>
              <tr> 
                <td class="tdheader">Description : </td>
                <td><textarea class="text" name="description" cols="55" rows="20">' . htmlentities($rs['description']) . '</textarea></td>
              </tr>
              
              <tr> 
                <td class="tdheader">Sequence :</td>
                <td><input type="text" class="text" name="seq" size="3" value="' . $rs['seq'] . '"></td>
              </tr>
              
              <tr> 
                <td align="center" colspan=2>
                  <input type="image" src="../images/admin/bt_cancel.gif" width="78" height="23" onclick="adminEditCancel(\'edit_area\')"> 
                  <input type="image" src="../images/admin/bt_save.gif" width="76" height="22" onclick="form1.submit"> 
                </td>
              </tr>
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
          </form></span>';
} elseif ($type == 21) {
    if ($id == 1) {
        $str = '';
        $sql = "SELECT `id`, `name` FROM `category` WHERE `fid` = 0 ORDER BY `seq` ASC, `id` DESC";
    	$query = $db->query($sql);
    	while($rs1 = $db->fetch_array($query)) {
    	    //$photo_category_ary[$rs1['id']] = $rs1['name'];
    	    $str .= '<option value="' . $rs1['id'] . '">' . $rs1['name'] . '</option>';
    	}
    	
    	
        $str = '<select name="select2" class="form">
					<option value="" selected>---Please Select---</option>
					' . $str . '				
				</select><br><br>
				  <input type="image" src="../images/admin/excel.gif" width="148" height="24"> ';
    } elseif ($id == 2) {
        $str = '';
        $sql = "SELECT `id`, `name` FROM `inventory` ORDER BY `seq` ASC, `id` DESC";
    	$query = $db->query($sql);
    	while($rs1 = $db->fetch_array($query)) {
    	    //$photo_category_ary[$rs1['id']] = $rs1['name'];
    	    $str .= '<option value="' . $rs1['id'] . '">' . $rs1['name'] . '</option>';
    	}
    	
    	
        $str = '<select name="select2" class="form">
					<option value="" selected>---Please Select---</option>
					' . $str . '				
				</select><br><br>
				  <input type="image" src="../images/admin/excel.gif" width="148" height="24"> ';
    } else {
        //$str = 'Please select export type !';
        $str = '';
    }
    
    $out_str ='<span id="edit_area">' . $str . '</span>';
} elseif ($type == 31) {
    $sql = "SELECT `password2` FROM `user` where `id` = '$id' LIMIT 1";
    $user_ary = $db->get_one($sql);
    	
    $str = '<form id="form_ax_' . $id . '" onsubmit="return false">
         <input type=text name="new_password" size=21 value="' . $user_ary['password2'] . '" class="text"><br>
         <input type=button value="Change"  onClick="on_ax_submit(\'' . $span_id . '\', 32, \'' . $id . '||||\' + form_ax_' . $id . '.new_password.value)" class="formText"> <input type=button value="Cancel" onclick="adminEditPassCancel(\'' . $span_id . '\',  \'' . $id . '\', \'' . $user_ary['password2'] . '\')" class="formText">
         </form>';

    $out_str ='<span id="' . $span_id . '">' . $str . '</span>';
} elseif ($type == 32) {
    list($id, $new_pwd) = explode("||||", $id);
    
    //str_replace('&nbsp;', '', $new_pwd);
    
    $sql = "SELECT `password2` FROM `user` where `id` = '$id' LIMIT 1";
    $user_ary = $db->get_one($sql);   
    
    
    if (strlen($new_pwd) > 32 || trim($new_pwd) == "") {
        $str = '<div onclick="getAdminEdit(\'' . $span_id . '\', \'31\', \'' . $id . '\')">' . $user_ary['password2'] . '<br><span style="color:red;">Update Failed</span></div>';
        $out_str ='<span id="' . $span_id . '">' . $str . '</span>';
        echo $out_str;
        exit;
    }
    
    $set_pwd = md5($new_pwd);
    $sql = "UPDATE `user` SET `password2` = '$new_pwd', `password` = '$set_pwd' WHERE id='$id' LIMIT 1";
    if ($db->query($sql)) {
        $str = '<div onclick="getAdminEdit(\'' . $span_id . '\', \'31\', \'' . $id . '\')">' . $new_pwd . '<br><span style="color:red;">Update Succeed</span></div>';
    } else {
        $str = '<div onclick="getAdminEdit(\'' . $span_id . '\', \'31\', \'' . $id . '\')">' . $user_ary['password2'] . '<br><span style="color:red;">Update Failed</span></div>';
    }
    
    $out_str ='<span id="' . $span_id . '">' . $str . '</span>';
} 

//$out_str = @mb_convert_encoding($out_str , 'UTF-8' , 'GB2312'  );
//echo "<iframe name='getdoiframe' width=0 height=0 src='about:blank' id='getdoiframe'></iframe>" . $out_str;
echo $out_str;

?>